import { ApiCall } from "tsrpc";
import { ReqOffer, ResOffer } from "../../../shared/master/auction/PtlOffer";
import { player, wallet_key } from "../../../model/fight/body/player";
import manage_auction from "../../model/manage/manage_auction";
import { template } from "../../../shared/master/MsgAction";
import app from "../../../app";

export default async function (call: ApiCall<ReqOffer, ResOffer>) {
    call.succ({})
    let user = call.req._player as player;
    if (!manage_auction.auctionNow) {
        user.sendMsg(template.default, '拍卖行当前还没有正在拍卖的道具')
        return;
    }
    let gold = user.wallet_get(wallet_key.gold)
    let needGold = call.req.num + manage_auction.nowPrice.price;
    if(gold < needGold){
        user.sendMsg(template.default, `金币不足出价失败\n您当前有:${gold}💰\n当前价格:${manage_auction.nowPrice.price}💰`);
        return;
    }
    user.wallet_change(wallet_key.gold,-needGold)
    manage_auction.price(user.uuid, user.name, call.req.num)
    user.sendMsg(template.default, `您已出价${app.BN(needGold)}💰`)
}